package com.fat.spzx.manager.controller;

import com.fat.spzx.manager.service.SysUserService;
import com.fat.spzx.model.dto.system.AssginRoleDto;
import com.fat.spzx.model.dto.system.SysRoleDto;
import com.fat.spzx.model.dto.system.SysUserDto;
import com.fat.spzx.model.entity.system.SysUser;
import com.fat.spzx.model.vo.common.Result;
import com.fat.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户接口
 * @author : fat
 */
@Tag(name = "用户模块接口")
@RestController
@RequestMapping(value = "/admin/system/sysUser")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    /**
     * 用户条件分页查询接口
     */
    @Operation(summary = "用户条件分页查询接口")
    @GetMapping(value = "/findByPage/{current}/{limit}")
    public Result findByPage(@PathVariable("current") Integer current,
                             @PathVariable("limit") Integer limit,
                              SysUserDto sysUserDto){
        PageInfo<SysUser> pageInfo = sysUserService.findByPageUser(current,limit,sysUserDto);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    /**
     * 用户添加
     */
    @Operation(summary = "用户添加")
    @PostMapping(value = "/saveSysUser")
    public Result saveUser(@RequestBody SysUser sysUser){
        sysUserService.saveSysUser(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 用户修改
     */
    @Operation(summary = "用户修改")
    @PutMapping(value = "/updateUser")
    public Result updateUser(@RequestBody SysUser sysUser){
        sysUserService.updateUser(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 用户删除
     */
    @Operation(summary = "用户删除")
    @DeleteMapping(value = "/deleteUser/{id}")
    public Result deleteUser(@PathVariable("id") Integer id){
        sysUserService.deleteById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 用户角色分配
     */
    @Operation(summary = "用户角色分配")
    @PostMapping("/doAssign")
    public Result doAssign(@RequestBody AssginRoleDto assginRoleDto) {
        sysUserService.doAssign(assginRoleDto) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }
}
